/*
 * @Author: webkaifa
 * @Date: 2020-08-25 20:09:21
 * @LastEditTime: 2020-09-29 18:10:48
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /out/awe-web/unitil工具类/utils.js
 */


/**
 * @description: 
 * @param {arr} 传入数组 [1,2,3,4,5,6]
 * @param {num} 传入分组列数 num 2 默认为1
 * @return {arr} 返回切割的二维数组
 */
export function arrTrans(arr, num = 1) {
    const newArr = [];
    const arrs = [...arr]
    while (arrs.length > 0) {
        newArr.push(arrs.splice(0, num));
    }
    return newArr;
}


/**
 * @description: 优化了横纵坐标最大值
 * @param {num} value 344
 * @return {num} 返回最大值
 */
export const totalNumberFormat = function (value) {
    var double = 10
    var _len = value.toString().length
    var num = Number(_len - 1)
    if (value < 1) {
        return Math.pow(double, num || 1)
    } else {
        var fist = value.toString().slice(0, 1)
        fist++
        return fist * Math.pow(double, num || 1)
    }
}


//挂载js脚本
export function loadJsFile(src) {
  return new Promise((resolve, reject) => {
    const script = document.createElement("script");
    script.type = "text/javascript";
    script.src = src
    script.onerror = reject;
    script.onload = resolve;
    document.head.appendChild(script);
  })
}